import { startDevice, stopDevice, updateDevice, deleteDevice  } from '../services/devices';

import { Message } from '@alifd/next';

const msg = {
    START_SUCCESS: 'Start Success',
    START_ERROR: 'Start Error',
    STOP_SUCCESS: 'Stop Success',
    STOP_ERROR: 'Stop Error',
    UPDATE_SUCCESS: 'Update Success',
    UPDATE_ERROR: 'Update Error',
    DELETE_SUCCESS: 'Delete Success',
    DELETE_ERROR: 'Delete Error',
}

// 启动设备
const handleStart = (id) => {
    startDevice(id).then(res => {
        if(res.code == 200) {
            Message.success(msg['START_SUCCESS'])
        } else {
            Message.error(msg['START_ERROR'])
        }
    })
};

// 暂停设备
const handleStop = (id) => {
    stopDevice(id).then(res => {
        if(res.code == 200) {
            Message.success(msg['STOP_SUCCESS'])
        } else {
            Message.error(msg['STOP_ERROR'])
        }
    })
};

// 更新设备
const handleUpdate = (id) => {
    updateDevice(id).then(res => {
        if(res.code == 200) {
            Message.success(msg['UPDATE_SUCCESS'])
        } else {
            Message.error(msg['UPDATE_ERROR'])
        }
    })
};

// 删除设备
const handleDelete = (id) => {
    deleteDevice(id).then(res=> {
        if(res.code == 200) {
            Message.success(msg['DELETE_SUCCESS'])
        } else {
            Message.error(msg['DELETE_ERROR'])
        }
    })
};

export default {
    START: handleStart,
    STOP: handleStop,
    UPDATE: handleUpdate,
    DELETE: handleDelete
}